/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.io.File;

/**
 * <p>Project: JavaStudy - Rename
 * <p>Powered by jiangbo On 2023-01-03
 * 19:53:48
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Rename {
        public static void main(String[] args) {
            //目标文件路径
            String src = "C:\\Users\\30444\\Desktop\\截图";
            File f = new File(src);
System.out.println(f.exists());
System.out.println(f.isFile());
System.out.println(f.isDirectory());
            if(f.isDirectory()){
                File[] fs = f.listFiles();
                int index = 0;
                for(File s :fs){
                    String filename = s.getName().toLowerCase();
                    String ext = filename.substring(filename.lastIndexOf("."));
                    if(".png".equalsIgnoreCase(ext)) {
                        String path = s.getParentFile().getName();
                        String newfilename = String.format("wang_%03d%s", ++index, ext);
                        s.renameTo(new File("C:\\Users\\30444\\Desktop\\截图", newfilename));
                    }
                }
            }
        }

    }


